#include "list.h"

#define NAMESIZE 32

struct score_st
{
	int id;
	char name[NAMESIZE];
	int math;
	int chinese;
	struct list_head node;
};
void print_s(struct score_st *d)
{
	printf("%d %s %d %d\n", d->id, d->name, d->math, d->chinese);
}
int main(void)
{
	struct score_st *datap;
	struct list_head *cur;
	LIST_HEAD(head);

	for (int i = 0; i < 7; i++)
	{
		datap = malloc(sizeof(struct score_st));
		if (datap == NULL)
			exit(1);
		datap->id = i;
		snprintf(datap->name, NAMESIZE, "stu%d", i);
		datap->math = rand() % 99;
		datap->chinese = rand() % 99;
		list_add(&datap->node, &head);
	}

	__list_for_each(cur, &head)
	{
		datap = list_entry(cur, struct score_st, node);
		print_s(datap);
	}

	printf("search for id =5 \n");
	__list_for_each(cur, &head)
	{
		datap = list_entry(cur, struct score_st, node);
		if (datap->id == 5)
			break;
	}
	if (cur == &head)
		printf("Can not find\n");
	else
		print_s(datap);

	return 0;
}